<!-- 本页样式 -->
<style scoped>
.del-dialog-cnt {
	font-size: 16px;
	text-align: center;
}
</style>
<!-- 页面布局-->
<template>
	<div class="table">
		<!-- 标题导航栏 -->
		<div class="title-box crumbs">
			<el-breadcrumb separator="/">
				<el-breadcrumb-item>
					<i class="el-icon-tickets"></i>&nbsp;&nbsp;预警设置
				</el-breadcrumb-item>
				<el-breadcrumb-item>查询列表</el-breadcrumb-item>
			</el-breadcrumb>
		</div>
		<!-- 主体区 -->
		<div class="container">
			<!-- 查询条件 -->
			<div class="search-box">
				<div class="search-item-box">
					<table>
						<tr>
							<!-- <td><i class="el-icon-search"></i></td>  -->

							<td class="search_td">&nbsp;</td>
							<td class="search_td">&nbsp;</td>
							<td class="search_td">&nbsp;</td>
							<td class="search_td">&nbsp;</td>
						</tr>
					</table>
				</div>
				<div class="search-button-box">
					<!-- <el-button type="primary" icon="search" @click="searchLoad">查询</el-button> -->
					<el-button type icon="add" @click="toAdd">添加</el-button>
				</div>
			</div>
			<!-- 查询条件END -->
			<!-- 数据列表 -->
			<div class="grid-data-box">
				<el-table
					:data="tableData"
					border
					:header-cell-style="{background:'#F3F3F3',color:'#606266'}"
					style="width: 100%"
					ref="multipleTable"
					@row-dblclick="clickToView"
					@sort-change="handleSortChange"
				>
					<!-- <el-table-column type="selection" width="40"></el-table-column>  -->
					<el-table-column type="index" label="序号" width="50"></el-table-column>
					<el-table-column prop="delay" label="系统采样间隔（分钟）"></el-table-column>
					<el-table-column prop="cpu" label="CPU告警值（%）"></el-table-column>
					<el-table-column prop="disk" label="硬盘告警值（%）"></el-table-column>
					<el-table-column prop="mem" label="内存告警值（%）"></el-table-column>
					<el-table-column prop="email" label="警告接受邮箱"></el-table-column>
					<el-table-column prop="createtime" label="创建时间" width="150"></el-table-column>
					<el-table-column label="操作" width="120">
						<template slot-scope="scope">
							<el-button size="mini" @click="toUpd( scope.row)" type="primary">编辑</el-button>
							<el-button size="mini" type="danger" @click="toDel( scope.row)" style="margin-left:5px">删除</el-button>
						</template>
					</el-table-column>
				</el-table>
			</div>
			<!-- 数据列表END -->
			<!-- 翻页导航条 -->
			<div class="navigate-box">
				<div class="pagination">
					<el-pagination
						background
						@current-change="handleCurrentChange"
						:total="parampters.totalCount"
						@size-change="handleSizeChange"
						:current-page.sync="parampters.pageIndex"
						:page-sizes="[20, 50, 100, 200]"
						:page-size="parampters.pageRows"
						layout="total, sizes, prev, pager, next"
					></el-pagination>
				</div>
			</div>
			<!-- 翻页导航条END -->
		</div>
		<!-- 主体区END -->
	</div>
</template>

<script>
import detailModel from "views/tsm/sys/ctrlparams_upd.vue";
export default {
	data() {
		return {
			// 筛选条件
			parampters: {
				//查询参数
				id: "",

				loginsid: "", //登录会话SID
				pageRows: 20, //每页行数
				pageCount: 0, //总页数
				pageIndex: 0, //当前页
				totalCount: 0 //总记录数
			},
			// 查询出的表格数据
			tableData: [],
			// 表格多选数据数组
			multipleSelection: [],
			// 表格操作数据所在行的索引
			idx: -1,
			//confirm提示信息弹框
			confirmBox: null,
			//所选记录id
			selectedId: "",
			//事物类型
			actType: "list",
			dicts: {}
		};
	},
	// 进入页面加载数据
	activated() {
		this.handleInitLoad();
	},
	methods: {
		/**
		 * 初始加载字典选项
		 */
		initSelectOptoins() {
			//this.loadSelectOptoins("usertype",null);
		},
		/**
		 * 通用定义方法：加载下拉选择 字典
		 *  @augments dictKind 字典类型
		 */
		loadSelectOptoins(dictKind, params) {
			this.$dicts
				.loadDict(this.httpRoot.BASEURL_TSM, params, dictKind)
				.then(res => {
					this.$set(this.dicts, dictKind, res);
				});
		},

		/**
		 * @augments  row 行所在的数据
		 * 表格数据列 内容字典转换
		 */

		formatter(row, column) {
			//if (column.property == 'type') {
			//    return this.$dicts.transDict(this.dicts.usertype, 'code', 'name', row.type);
			//}
			return "";
		},

		/**
		 * @augments column
		 * @augments prop 排序字段
		 * @augments order  排序顺序 ascending 升序  descending 降序
		 * 排序点击方法
		 */
		handleSortChange(column, prop, order) {
			if (order == "ascending") {
				// 升序
			} else if (order == "descending") {
				// 降序
			}
		},

		/**
		 * @augments val 页码
		 * 切换页码操作
		 */
		handleCurrentChange(val) {
			this.parampters.pageIndex = val;
			// 重新获取当前页码的数据
			this.searchLoad();
		},

		/**
		 * @augments val 每页显示条数
		 * 每页显示条数修改
		 */
		handleSizeChange(val) {
			// 修改每页显示条数
			this.parampters.pageRows = val;
			// 重新获取数据
			this.searchLoad();
		},

		/**
		 * 组件初始化加载
		 */
		handleInitLoad() {
			this.initSelectOptoins();
			this.searchLoad();
		},
		/**
		 * 条件筛选查询,加载数据
		 */
		searchLoad() {
			this.parampters = this.$util.trimObjStr(this.parampters);
			this.parampters.loginsid = this.$util.getLoginer().sessionId;
			this.$axios
				.get(this.httpRoot.BASEURL_TSM + "rest/tsm/sys/ctrlparams/tolist", {
					params: this.parampters
				})
				.then(res => {
					if (res.data.result == "true") {
						let data = res.data; //
						this.tableData = data.resultData;
						this.parampters.pageIndex = parseInt(data.pageIndex);
						this.parampters.pageCount = parseInt(data.pageCount);
						this.parampters.totalCount = parseInt(data.totalCount);
					} else {
						this.$error(
							"查询失败" +
								res.data.resultMessage +
								",错误代码:" +
								res.data.resultCode
						);
					}
				})
				.catch(function(error) {});
		},

		/**
		 * 新增记录信息
		 */
		toAdd() {
			//页面参数
			var pageParam = {
				actType: "add",
				seleid: "-1"
			};
			//this.$router.push({
			//  path: "/ctrlparamsDetail",
			//  query: pageParam
			//});
			this.toShowDetail("新增信息", pageParam, 800, 450);
		},

		/**
		 * 修改记录信息
		 * @augments index 编辑数据所在的行索引
		 * @augments row 编辑数据行的数据
		 */
		toUpd(row) {
			this.selectedId = row.id;
			//页面参数
			var pageParam = {
				actType: "upd",
				seleid: this.selectedId
			};
			//this.$router.push({
			//  path: "/ctrlparamsDetail",
			//  query: pageParam
			//});
			this.toShowDetail("修改信息", pageParam, 800, 450);
		},
		//
		clickToView(rowData, column) {
			this.toView(rowData);
		},
		/**
		 * 查看记录信息
		 * @augments row 编辑数据行的数据
		 * @augments ev
		 */
		toView(row) {
			this.selectedId = row.id;
			//页面参数
			var pageParam = {
				actType: "view",
				seleid: this.selectedId
			};
			//this.$router.push({
			//  path: "/ctrlparamsDetail",
			//  query: pageParam
			//});
			this.toShowDetail("查看信息", pageParam, 800, 450);
		},

		/**
		 * 删除记录信息
		 * @augments index 所在表格行的索引
		 * @augments row 所在表格行的所有数据对象
		 */
		toDel(row) {
			this.selectedId = row.id;
			this.confirmBox = this.$dialog.confirm("确定删除所选记录吗？");
			this.confirmBox.exec.then(btnName => {
				if (btnName == "ok") {
					// 确定删除数据操作
					this.$axios
						.post(
							this.httpRoot.BASEURL_TSM + "rest/tsm/sys/ctrlparams/delsave",
							{
								loginsid: this.$util.getLoginer().sessionId,
								id: this.selectedId
							}
						)
						.then(res => {
							if (res.data.result == "true") {
								this.$dialog.close(this.confirmBox.vm);
								this.$message.success("删除成功");
								this.searchLoad();
							} else {
								this.$dialog.close(this.confirmBox.vm);
								this.$error(
									"删除失败：" +
										res.data.resultMessage +
										",错误代码:" +
										res.data.resultCode
								);
							}
						});
				} else {
					this.$dialog.close(this.confirmBox.vm); // 取消删除数据操作
				}
			});
		},
		//详细窗口弹出
		toShowDetail(title, dialogParams, w, h) {
			let commDialog = this.$dialog.commDialog(
				title,
				detailModel,
				dialogParams,
				w + "px",
				h + "px"
			);
			commDialog.exec.then(resp => {
				if (resp.type == "ok") {
					this.searchLoad();
				} else if (resp.type == "cancel") {
				}
			});
		}
	}
};
</script>
